#region Copyright
/// <copyright>
/// Copyright (c) 2007 Ilia Shramko.
/// Released under the terms of the GNU General Public License.
/// </copyright>
#endregion

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Text;

namespace Osh.Configuration
{
	public interface IOshSection : IConfigurationSection
	{
		string Theme { get; set; }
		bool AutoSwitchMode { get; set; }
		LogotypesElement Logotypes { get; set; }
		PlaybackElement Playback { get; set; }
		EpgElement Epg { get; set; }
		TeletextElement Teletext { get; set; }
		PlayerCollection Players { get; }
		MediaLibraryCollection MediaLibraries { get; }
		ModeCollection Modes { get; }
		ScreenCollection Screens { get; }
	}

	/// <summary>
	/// OshSection is the root configuration section class of OSH.
	/// </summary>
	/// <remarks>
	/// ConfigurationSection class and many others are hidden from COM
	/// (have ComVisible(false) attribute at the assembly level).
	/// Because of this we have to hide this class from COM completly
	/// (using ClassInterface(ClassInterfaceType.None) attribute) to avoid 0x80131509 error
	/// and provide access to the class through a separate interface.
	/// </remarks>
	[ClassInterface(ClassInterfaceType.None)]
	public class OshSection : ConfigurationSection, IOshSection
	{
		public OshSection()
		{
		}

		[ConfigurationProperty("theme", DefaultValue = "MCE", IsRequired = true)]
		[StringValidator(MinLength = 1)]
		public string Theme
		{
			get { return (string)this["theme"]; }
			set { this["theme"] = value; }
		}

		[ConfigurationProperty("autoSwitchMode")]
		public bool AutoSwitchMode
		{
			get { return (bool)base["autoSwitchMode"]; }
			set { base["autoSwitchMode"] = value; }
		}

		[ConfigurationProperty("logotypes")]
		public LogotypesElement Logotypes
		{
			get { return (LogotypesElement)this["logotypes"]; }
			set { this["logotypes"] = value; }
		}

		[ConfigurationProperty("playback")]
		public PlaybackElement Playback
		{
			get { return (PlaybackElement)this["playback"]; }
			set { this["playback"] = value; }
		}

		[ConfigurationProperty("epg")]
		public EpgElement Epg
		{
			get { return (EpgElement)this["epg"]; }
			set { this["epg"] = value; }
		}

		[ConfigurationProperty("teletext")]
		public TeletextElement Teletext
		{
			get { return (TeletextElement)this["teletext"]; }
			set { this["teletext"] = value; }
		}

		[ConfigurationProperty("players")]
		public PlayerCollection Players
		{
			get { return (PlayerCollection)this["players"]; }
		}

		[ConfigurationProperty("mediaLibraries")]
		public MediaLibraryCollection MediaLibraries
		{
			get { return (MediaLibraryCollection)this["mediaLibraries"]; }
		}

		[ConfigurationProperty("modes")]
		public ModeCollection Modes
		{
			get { return (ModeCollection)this["modes"]; }
		}

		[ConfigurationProperty("screens")]
		public ScreenCollection Screens
		{
			get { return (ScreenCollection)this["screens"]; }
		}

		public bool IsMediaPlayerEnabled(string playerName)
		{
			foreach(PlayerElement playerElement in this.Players)
				if(playerElement.Name == playerName && playerElement.Enabled)
					return true;
			return false;
		}
	}
}
